<template>
  <div>
    <div class="node" v-has="{action: 'equipmentExtraSichuansheng:list', effect: 'move'}">
    <Panel title="充电站扩展信息列表" useBack>
      <div slot='ext' class="examine">
        <el-button size="mini" v-has="{action: 'equipmentExtraSichuansheng:add', effect: 'move'}" class="button-offt" type="success" icon="el-icon-plus" @click="()=>editStore()">新增</el-button>
      </div>
    <TableEncapsulation
      slot="body"
      :tableConfig="tableConfig"
      :tableData="tableData"
    >
    <template slot="operation" slot-scope="operation">
          <el-button 
          v-has="{action: 'equipmentExtraSichuansheng:update', effect: 'move'}"
          type="text" @click="()=>updateExtend(operation.row.id, operation.row.pileName)">编辑扩展信息</el-button>
        </template>
        <TablePager
          slot="pager"
          v-if="pager.use"
          :size="pager.size"
          :pageChange="pageChange"
          :show-total="pager.showTotal"
          :total="pager.total"
          :current="pager.current"
        >
          <span class="demonstration">GO></span>
        </TablePager>
    </TableEncapsulation>
    </Panel>
    <!-- 添加编辑 start-->
    <ModalPanel 
      :visible='visible'
      title="添加/编辑"
      :onCancel="onCancel"
      class="bannerDialog"
      :onOk="onSubmit">
      <div>
        <ModifyForm
          :hiddenBtn='true'
          :editColumn='editColumn'
          :updateData="updateData"
          labelWidth='100px'
          ref="configModal"
          class="ModifyForm"
          :temporaryData='modalData'>
        </ModifyForm>
      </div>
    </ModalPanel>
    <!-- 添加编辑end -->
    </div>
    <div style="display: none;width:100%;height:100%;margin: auto;" v-has="{action: 'equipmentExtraSichuansheng:list', effect: 'noPremiss'}">
      <NoPremission></NoPremission>
    </div>
  </div>
</template>
<script>
import request from "@/tools/request";
import Panel from "@/components/Panel";
import TableEncapsulation from "@/components/TableEncapsulation";
import TablePager from "@/components/Pager";
import SearchInput from "@/components/SearchInput";
import SearchSelect from "@/components/SearchSelect";
import { objectFilter } from "@/tools/array";
import ModifyForm from "@/components/ModifyForm";
import ModalPanel from "@/components/ModalPanel";
export default {
  name: "pileextendlist",
  components: {
    TableEncapsulation,
    TablePager,
    Panel,
    SearchInput,
    SearchSelect,
    ModifyForm,
    ModalPanel
  },
  data() {
    return {
      tableData: [],
      siteList: [],
      searchs: {
        component: 'pile',
        site:"",
        sn: '',
        name: '',
        deviceId:'',
        type:'',
        state:'',
      },
      // selectValue: [],
      // loading:false,
      deviceList:[],
      pager: {
        component: 'pile',
        use: true,
        total: 0,
        current: 1,
        size: 10,
        showTotal: true
      },
      operation: true,
      //添加编辑
      visible:false,
      modalData:{},
      editColumn: [
        {
          name: "站点",
          prop: "stationId",
          type: "select",
          optionBindLabel: 'stationName',
          optionBindValue: 'id',
          optionList: [{'id':'','stationName':'充电站'}],
          onChange: () => {},
          required:true,
          width:24
        },
        {
          name: "是否独立报桩",
          prop: "isAloneApply",
          type: "radio",
          optionBindLabel: 'name',
          optionBindValue: 'id',
          optionList: [{'id': true,'name': "是"},{'id':false, 'name':"否"}],
          width:24,
          onChange: () => {},
          required: true
        }, 
        {
          name: "国网电费账单户号",
          prop: "accountNumber",
          type: "text",
          width:24,
          desc:'独立报桩必填',
          required: false
        },
        {
          name: "容量",
          prop: "capacity",
          type: "text",
          width:24,
          desc:'独立报桩必填',
          required: false
        },
        {
          name: "停车收费类型",
          prop: "parkFeeType",
          type: "radio",
          optionBindLabel: 'name',
          optionBindValue: 'id',
          optionList: [{'id': 1,'name': "自营"},{'id':2, 'name':"第三方"},{'id':3, 'name':"租用"},{'id':9, 'name':"私人"}],
          width:24,
          onChange: () => {},
          required: true
        }, 
        {
          name: "是否配备卫生间",
          prop: "toiletFlag",
          type: "radio",
          optionBindLabel: 'name',
          optionBindValue: 'id',
          optionList: [{'id': true,'name': "是"},{'id':false, 'name':"否"}],
          width:24,
          onChange: () => {},
          required: true
        }, 
        {
          name: "是否配备便利店",
          prop: "storeFlag",
          type: "radio",
          optionBindLabel: 'name',
          optionBindValue: 'id',
          optionList: [{'id': true,'name': "是"},{'id':false, 'name':"否"}],
          width:24,
          onChange: () => {},
          required: true
        }, 
        {
          name: "是否配备休息室",
          prop: "loungeFlag",
          type: "radio",
          optionBindLabel: 'name',
          optionBindValue: 'id',
          optionList: [{'id': true,'name': "是"},{'id':false, 'name':"否"}],
          width:24,
          onChange: () => {},
          required: true
        },
        {
          name: "是否配备雨棚",
          prop: "canopyFlag",
          type: "radio",
          optionBindLabel: 'name',
          optionBindValue: 'id',
          optionList: [{'id': true,'name': "是"},{'id':false, 'name':"否"}],
          width:24,
          onChange: () => {},
          required: true
        }, 
        {
          name: "是否有小票机",
          prop: "printerFlag",
          type: "radio",
          optionBindLabel: 'name',
          optionBindValue: 'id',
          optionList: [{'id': true,'name': "是"},{'id':false, 'name':"否"}],
          width:24,
          onChange: () => {},
          required: true
        }, 
        {
          name: "是否有道闸",
          prop: "barrierFlag",
          type: "radio",
          optionBindLabel: 'name',
          optionBindValue: 'id',
          optionList: [{'id': true,'name': "是"},{'id':false, 'name':"否"}],
          width:24,
          onChange: () => {},
          required: true
        },
        {
          name: "是否有地锁",
          prop: "parkingLockFlag",
          type: "radio",
          optionBindLabel: 'name',
          optionBindValue: 'id',
          optionList: [{'id': true,'name': "是"},{'id':false, 'name':"否"}],
          width:24,
          onChange: () => {},
          required: true
        }, 
        {
          name: "是否参与需求响应",
          prop: "isDemandResponse",
          type: "radio",
          optionBindLabel: 'name',
          optionBindValue: 'id',
          optionList: [{'id': true,'name': "是"},{'id':false, 'name':"否"}],
          width:24,
          onChange: () => {},
          required: true
        },
        {
          name: "是否有序充电场站",
          prop: "isSupportOrderlyCharging",
          type: "radio",
          optionBindLabel: 'name',
          optionBindValue: 'id',
          optionList: [{'id': true,'name': "是"},{'id':false, 'name':"否"}],
          width:24,
          onChange: () => {},
          required: true
        }, 
        {
          name: "是否有储能设备",
          prop: "isEnergyStorage",
          type: "radio",
          optionBindLabel: 'name',
          optionBindValue: 'id',
          optionList: [{'id': true,'name': "是"},{'id':false, 'name':"否"}],
          width:24,
          onChange: () => {},
          required: true
        }, 
      ],
      //添加编辑end
    };
  },
  mounted() {
    this.getData();
    this.getStation()
  },
  computed: {
    tableConfig () {
      return {
        selection: false,
        columnConfig: [
          {
            label: "桩名称",
            type: "text",
            prop: "pileName",
            align: "center"
          },
          {
            label: "是否独立报桩",
            type: "other",
            prop: "isAloneApply",
            align: "center",
            fnc: val => val  ? '是':  '否',
            class: val => val ? 'agree': 'cancel'
          },
          {
            label: "国网电费账单户号",
            type: "text",
            prop: "accountNumber",
            align: "center"
          },
          {
            label: "容量",
            type: "text",
            prop: "capacity",
            align: "center"
          },
          {
            label: "停车收费类型",
            type: "other",
            prop: "equipmentClassification",
            align: "center",
            fnc: val => val==1  ? '自营':  val==2  ? '第三方':val==2  ? '租用':'私人',
          },
          {
            label: "是否配备卫生间",
            type: "other",
            prop: "toiletFlag",
            align: "center",
            fnc: val => val  ? '是':  '否',
            class: val => val ? 'agree': 'cancel'
          },
          {
            label: "是否配备便利店",
            type: "other",
            prop: "storeFlag",
            align: "center",
            fnc: val => val  ? '是':  '否',
            class: val => val ? 'agree': 'cancel'
          },
          {
            label: "是否配备休息室",
            type: "other",
            prop: "loungeFlag",
            align: "center",
            fnc: val => val  ? '是':  '否',
            class: val => val ? 'agree': 'cancel'
          },
          {
            label: "设备生产商名称",
            type: "text",
            prop: "manufacturerName",
            align: "center"
          },
          {
            label: "是否配备休息室",
            type: "other",
            prop: "loungeFlag",
            align: "center",
            fnc: val => val  ? '是':  '否',
            class: val => val ? 'agree': 'cancel'
          },
          {
            label: "是否配备雨棚",
            type: "other",
            prop: "canopyFlag",
            align: "center",
            fnc: val => val  ? '是':  '否',
            class: val => val ? 'agree': 'cancel'
          },
          {
            label: "是否有小票机",
            type: "other",
            prop: "printerFlag",
            align: "center",
            fnc: val => val  ? '是':  '否',
            class: val => val ? 'agree': 'cancel'
          },

          {
            label: "是否有道闸",
            type: "other",
            prop: "barrierFlag",
            align: "center",
            fnc: val => val  ? '是':  '否',
            class: val => val ? 'agree': 'cancel'
          },
          {
            label: "是否有地锁",
            type: "other",
            prop: "parkingLockFlag",
            align: "center",
            fnc: val => val  ? '是':  '否',
            class: val => val ? 'agree': 'cancel'
          },
          {
            label: "是否参与需求响应",
            type: "other",
            prop: "isDemandResponse",
            align: "center",
            fnc: val => val  ? '是':  '否',
            class: val => val ? 'agree': 'cancel'
          },
          {
            label: "是否有序充电场站",
            type: "other",
            prop: "isSupportOrderlyCharging",
            align: "center",
            fnc: val => val  ? '是':  '否',
            class: val => val ? 'agree': 'cancel'
          },
          {
            label: "是否有储能设备",
            type: "other",
            prop: "isEnergyStorage",
            align: "center",
            fnc: val => val  ? '是':  '否',
            class: val => val ? 'agree': 'cancel'
          },
          this.operation && {
            type: "operation",
            align: "center",
            label: "操作",
            width:180
          }
        ].filter(Boolean)
        }
    }
  },
  methods: {
    //获取站点
    async getStation(){
      let { data } = await request({
      url: "/manage/station/select",
      method: "POST",
      data: {}
      });
      this.editColumn[0].optionList = data
    },
    async getData() {
      let current = this.pager.current
      let size = this.pager.size
      let search = objectFilter({current, size })
      const res = await request({
        url: "/manage/station/extra/chengdushi/query",
        method: "POST",
        data:  search
      });
      this.tableData = res.page.records
      this.pager.total = res.page.total
      this.pager.current = res.page.current
    },
    pageChange(val) {
      this.pager.current = val;
      this.getData();
    },
    searchSelect(key, val){
      this.searchs[key] = val;
      this.pager.current = 1;
      this.getData()
    },
    
    changeSearch(key, val) {
      this.searchs[key] = val;
      this.pager.current = 1;
    },
    updateExtend(id, name){
      this.$router.push({ path: "/extra/site/city/info", query:{id,name}})
    },
    //添加编辑start
    editStore(rowData){
      if(rowData){
        this.modalData = {...rowData}
      }else{
        this.modalData ={}
      }
      this.visible = true
    },
    async onSubmit(){
      this.$refs['configModal'].onSubmit()
    },
    onCancel(){
      this.visible = false
    },
    async updateData(values){
      let stationId = this.stationId
      const { id, isAloneApply, accountNumber, capacity, parkFeeType, toiletFlag, storeFlag
      , loungeFlag, canopyFlag, printerFlag, barrierFlag, parkingLockFlag, isDemandResponse
      , isSupportOrderlyCharging, isEnergyStorage} = values
      let url = id ? "/manage/station/extra/chengdushi/update" : "/manage/station/extra/chengdushi/add"
      let msg = id ? "编辑成功" : "添加成功"
      let res = await request({
        url: url,
        method: 'POST',
        data: { id, stationId, isAloneApply, accountNumber, capacity, parkFeeType, toiletFlag, storeFlag
      , loungeFlag, canopyFlag, printerFlag, barrierFlag, parkingLockFlag, isDemandResponse
      , isSupportOrderlyCharging, isEnergyStorage }
      })
      if(res.code !==0) return
        this.$message.success(msg)
        this.visible = false
        this.getData();
      },
  }
}
</script>
<style lang='scss' >

</style>